﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using nplJobsCommon.JobSeeker;
using System.Data.SqlClient;

namespace nplJobsDAL.Insert
{
    /// <summary>
    /// This class is used to insert job seeker's data
    /// </summary>
    public class InsertJobSeeker : DataAccessBase
    {
        public Guid lastJobSeekerID;
        public string CheckUnique;
        
        public JobSeeker JobSeeker { get; set; }

        public InsertJobSeeker()
        {
            StoredProcedureName = StoredProcedure.Name.spInsertJobSeeker.ToString();
        }

        public void Insert()
        {
            InsertJobSeekerDataParameters contactInsertDataParameters = new InsertJobSeekerDataParameters(this.JobSeeker);
            DataBaseHelper dbHelper = new DataBaseHelper(StoredProcedureName);
            dbHelper.Parameters = contactInsertDataParameters.Parameters;
            object LastJobSeekerID = dbHelper.RunScalar();

            if (LastJobSeekerID != null)
            {
                lastJobSeekerID = (Guid)LastJobSeekerID;
            }
            else
            {
                lastJobSeekerID = Guid.Empty;
            }
        }
    }

    #region SQL parameters for Job seeker insert data
    public class InsertJobSeekerDataParameters
    {      
        public int CkeckUnique;
        private SqlParameter[] _parameters;
        private SqlParameter[] _insertParam;
        public int lastJobSeekerID;

        public InsertJobSeekerDataParameters(JobSeeker jobSeeker)
        {
            this.JobSeeker = jobSeeker;
            Build();
        }

        #region spAddContact parameters
        /*
         
         */
        #endregion

        private void Build()
        {
            SqlParameter[] parameters = 
                {
                    //new SqlParameter("@JobSeekerID", JobSeeker.JobSeekerID),
                    //new SqlParameter("@FirstName", JobSeeker.FirstName),
                    //new SqlParameter("@LastName", JobSeeker.LastName),
                    //new SqlParameter("@DOB", JobSeeker.DOB),
                    //new SqlParameter("@GenderID", JobSeeker.GenderID),
                    //new SqlParameter("@NationalityID", JobSeeker.NationalityID),
                    //new SqlParameter("@MaritalStatusID", JobSeeker.MaritalStatusID),
                    //new SqlParameter("@AboutMe", JobSeeker.AboutMe),
                    //new SqlParameter("@Email", JobSeeker.Email),
                    //new SqlParameter("@AlternativeEmail", JobSeeker.AlternativeEmail),
                    //new SqlParameter("@PresentSalaryID", JobSeeker.PresentSalaryID),
                    //new SqlParameter("@ExpectedSalaryID", JobSeeker.ExpectedSalaryID),
                    //new SqlParameter("@PresentAddress", JobSeeker.PresentAddress),
                    //new SqlParameter("@PermanentAddress", JobSeeker.PermanentAddress),
                    //new SqlParameter("@MobilePhone", JobSeeker.MobilePhone),
                    //new SqlParameter("@HomePhone", JobSeeker.HomePhone),
                    //new SqlParameter("@Resume", JobSeeker.Resume),
                    //new SqlParameter("@Skills", JobSeeker.Skills),
                    //new SqlParameter("@Qualifications", JobSeeker.Qualifications),
                    //new SqlParameter("@Photo", JobSeeker.Photo),
                    //new SqlParameter("@LastJobSeekerID", lastJobSeekerID){ Direction= System.Data.ParameterDirection.ReturnValue},

                    new SqlParameter("@JobSeekerID", JobSeeker.JobSeekerID),
                    new SqlParameter("@FirstName", JobSeeker.FirstName),
                    new SqlParameter("@LastName", JobSeeker.LastName),
                    new SqlParameter("@DOB", JobSeeker.DOB),
                    new SqlParameter("@GenderID", JobSeeker.GenderID),
                    new SqlParameter("@NationalityID", JobSeeker.NationalityID),
                    new SqlParameter("@MaritalStatusID", JobSeeker.MaritalStatusID),
                    new SqlParameter("@AboutMe", JobSeeker.AboutMe),
                    new SqlParameter("@Email", JobSeeker.Email),
                    new SqlParameter("@AlternativeEmail", JobSeeker.AlternativeEmail),
                    new SqlParameter("@PresentSalaryID", JobSeeker.PresentSalaryID),
                    new SqlParameter("@ExpectedSalaryID", JobSeeker.ExpectedSalaryID),
                    new SqlParameter("@PostalAddress", JobSeeker.PostalAddress),
                    //new SqlParameter("@PermanentAddress", JobSeeker.PermanentAddress),
                    new SqlParameter("@MobilePhone", JobSeeker.MobilePhone),
                    new SqlParameter("@HomePhone", JobSeeker.HomePhone),
                    new SqlParameter("@Resume", JobSeeker.Resume),
                    new SqlParameter("@Skills", JobSeeker.Skills),
                    new SqlParameter("@Qualifications", JobSeeker.Qualifications),
                    new SqlParameter("@Photo", JobSeeker.Photo),

                    new SqlParameter("@CountryID", JobSeeker.CountryID),
                    new SqlParameter("@DivisionID", JobSeeker.DivisionID),
                    new SqlParameter("@DistrictID", JobSeeker.DistrictID),
                    new SqlParameter("@CityID", JobSeeker.CityID),
                    new SqlParameter("@UserType", JobSeeker.UserType),

                    new SqlParameter("@LastJobSeekerID", lastJobSeekerID){ Direction= System.Data.ParameterDirection.ReturnValue},

                };

            Parameters = parameters;


            //SqlParameter[] insertParam = 
            //    {
                   
            //        new SqlParameter("@FirstName", JobSeeker.FirstName),
            //        new SqlParameter("@LastName", JobSeeker.LastName),
            //        new SqlParameter("@DOB", JobSeeker.DOB),
            //        new SqlParameter("@NationalityID", JobSeeker.NationalityID),
            //        new SqlParameter("@AboutMe", JobSeeker.AboutMe),
            //        new SqlParameter("@Email", JobSeeker.Email),
            //         new SqlParameter("@GenderID", JobSeeker.GenderID),
            //        new SqlParameter("@PresentAddress", JobSeeker.PresentAddress),
            //        new SqlParameter("@MobilePhone", JobSeeker.MobilePhone),
                  
            //    };

            //_insertParam = insertParam;
        }

        public JobSeeker JobSeeker { get; set; }

        public SqlParameter[] Parameters
        {
            get { return _parameters; }
            set { _parameters = value; }
        }

        public SqlParameter[] InsertParam
        {
            get { return _insertParam; }
            set { _insertParam = value; }
        }
    }
    #endregion
}
